<?php

    //    ELGG courses admin panel page

    // Run includes
        require_once(dirname(dirname(dirname(__FILE__)))."/includes.php");
        require_once("lib.php");
        require_once(dirname(dirname(__FILE__))."/common.php");
        
    // Initialise functions for user details, icon management and profile management
        run("admin:init");

        define("context", "admin");
        templates_page_setup();
        if (!isadmin()){
        	$body  = templates_draw( array(
                               'context' => 'admin',
                               'title' => $title,
                               'body' => "You must be an admin to access this page",
                               ));

			echo templates_page_draw(array($title, $body));

        	return;
        }
        
$method = required_param('method', PARAM_ALPHA);

switch ($method){
	case 'addcourse':
		//check that date and courseid sent
		$courseName = required_param('coursename', PARAM_NOTAGS);
		$response = addAdminCourse($courseName);
		break;
	case 'deletecourse':
		//check that date and courseid sent
		$cid = required_param('cid', PARAM_INT);
		$response = deleteAdminCourse($cid);
		break;
	case 'editcourse':
		//check that date and courseid sent
		$cid = required_param('cid', PARAM_INT);
		$courseName = required_param('coursename', PARAM_NOTAGS);
		$response = editAdminCourse($cid,$courseName);
		break;
	case 'getcourse':
		//check that date and courseid sent
		$cid = required_param('cid', PARAM_INT);
		$response = getAdminCourse($cid);
		break;
	
}
        
// set header to be XML
header('Content-Type: text/xml;');
$str = '<?xml version="1.0" encoding="UTF-8"?>';
$str .= '<response>';
if ($response) {
	$str .= responseToXML($response);
}
$str .= '</response>';

echo $str;
        
?>
